#include<graphics.h>
#include<conio.h>

#pragma comment(lib,"Winmm.lib")

#define High 864
#define Width 591

IMAGE img_bk;
int position_x,position_y;
int bullet_x,bullet_y;
IMAGE img_planeNormal1,img_planeNormal2;
IMAGE img_bullet1,img_bullet2;

void startup()
{
	initgraph(Width,High);
	loadimage(&img_bk,"D:\\background.jpg");
	loadimage(&img_planeNormal1,"D:\\planeNormal_1.jpg");
	loadimage(&img_planeNormal2,"D:\\planeNormal_2.jpg");
	loadimage(&img_bullet1,"D:\\bullet1.jpg");
	loadimage(&img_bullet2,"D:\\bullet2.jpg");
	position_x=Width*0.5;
	position_y=High*0.7;
	bullet_x=position_x;
	bullet_y=-85;
	BeginBatchDraw();
}

void show()
{
	putimage(0,0,&img_bk);
	putimage(position_x-50,position_y-60,&img_planeNormal1,NOTSRCERASE);
	putimage(position_x-50,position_y-60,&img_planeNormal2,SRCINVERT);
	putimage(bullet_x-7,bullet_y,&img_bullet1,NOTSRCERASE);
	putimage(bullet_x-7,bullet_y,&img_bullet2,NOTSRCERASE);
	FlushBatcDraw();
	sleep(2);
}

void updateWithoutInput()
{
	if(bullet_y>-25)
		bullet_y=bullet_y-3;
}

void updateWithInput
{
	MOUSEMSG m;
	while(MousHit())
	{
		m=GetMouseMsg();
		if(m.uMsg==WM_MOUSEMOVE)
		{
			position_x=m.x;
			position_y=m.y;
		}
		else if(m.uMsg==WM_LBUTTONDOWN)
		{
			bullet_x=position_x;
			bullet_y=position_y-85;
		}
	}
}

void gameover()
{
	EndBatchDraw();
	getch();
	closegeaph();
}

int main()
{
	startup();
	while(1)
	{
		show();
		updateWithoutInput();
		updateWithInput();
	}
	gameover();
	return 0;
}